/**
 * Copyright (c) 2002-2011 旭鸣信息
 * All rights reserved. 
 * File：GoodsGroupContorller.java
 * History:
 *       May 13, 2012: Initially created, liuzhi.
 */
package com.xteam.ecsystem.contorller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tangkf.utils.bean.ReqHelper;
import com.xteam.ecsystem.service.admin.GoodsGroupAttrService;
import com.xteam.ecsystem.service.admin.SystemLogService;
import com.xteam.ecsystem.utils.ConstantLocation;

/**
 * 商品分类属性控制枢纽站
 * @author liuzhi
 *
 */
@Controller
public class GoodsGroupAttrContorller {

	@Autowired
	private GoodsGroupAttrService ggAttrService;
	
	@Autowired
	private SystemLogService logService;
	
	public void setToBeJsonType(HttpServletRequest request, HttpServletResponse response) {
		response.setContentType("application/json;charset=UTF-8");
	};
	
	@RequestMapping("/saveOrUpdateGGAttrInfo.do")
	public void saveOrUpdateGGAttrInfo(HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) throws IOException {
		String bgaGgroup = ReqHelper.getRequestString(request, "bggId");
		String bgaGtype = ReqHelper.getRequestString(request, "bgtId");
		String bgaTattri = ReqHelper.getRequestString(request, "btaIds");
		String gBggId = ReqHelper.getRequestString(request, "gBggId");
		String lslUser = ReqHelper.getRequestString(request, "lslUser");
		String lslAddress = ReqHelper.getRequestString(request, "lslAddress");
		
		this.ggAttrService.saveOrUpdateObject(bgaGgroup, bgaGtype, bgaTattri, gBggId);
		
		this.logService.saveSystemLogs(lslUser, lslAddress, ConstantLocation.LOG_GROUPATTR_MGR, 
				"saveOrUpdateObject", ConstantLocation.LOG_SAVE, "BaseGroupAttribute");
	}
	
	@RequestMapping("/getBggAttrByBgaGgroup.do")
	public void getBggAttrByBgaGgroup(HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap) throws IOException {
		setToBeJsonType(request, response);
		
		String bgaGgroup = ReqHelper.getRequestString(request, "bgaGgroup");
		String bggAttrList = this.ggAttrService.getBggAttrByBgaGgroup(bgaGgroup);
		response.getWriter().write(bggAttrList);
		
	}
	
}
